package summative;

public class Vector
{
	private int startX;
	private int startY;
	private int endX;
	private int endY;
	private double slope;

	private double length;
	private double scaledLength;
	private double angle;

	private String unitVector;

	private int drawCoordX;
	private int drawCoordY;
	private int drawCoordXF;
	private int drawCoordYF;

	private Boolean visibility = true;


	public Vector(int strtX, int strtY, int endX, int endY, Boolean mouseListener)
	{

		this.startX = strtX;
		this.startY = strtY;
		this.endX = endX;
		this.endY = endY;
		calculateSlope();
		calculateLengths();
		calculateAngle();
		convertToUnitVec(startX, startY, endX, endY);
		if(mouseListener==false)
		{
			calculateDrawCoords();
		}
		else
		{
			drawCoordX = startX;
			drawCoordY = startY;
			drawCoordXF = endX;
			drawCoordYF = endY; 
		}
	}

	public Vector(String unitVector)
	{
		this.unitVector = unitVector;
		this.startX = 348;
		this.startY = 358;
		calculateXUnitVec();
		calculateYUnitVec();
		calculateSlope();
		calculateLengths();
		calculateAngle();
		calculateDrawCoords();
	}

	public void calculateDrawCoords()
	{
		drawCoordX = (startX);
		drawCoordY = (startY);
		drawCoordXF = startX + endX;
		drawCoordYF = startY - endY; 
	}

	public void calculateXUnitVec()
	{
		String[] array;
		array = unitVector.split("i");

		endX = Integer.parseInt(array[0])*10;
	}

	public void toggleVisibility()
	{
		if(visibility == true)
		{
			visibility = false;
		}
		else
		{
			visibility = true;
		}
	}

	public void calculateYUnitVec()
	{
		String[] arrayOne;
		arrayOne = unitVector.split("i");

		String[] arrayTwo;
		arrayTwo = arrayOne[1].split("\\+");

		String[] arrayThree;
		arrayThree = arrayTwo[1].split("j");

		endY = (Integer.parseInt(arrayThree[0].trim())*10);
	}

	public void calculateSlope()
	{
		this.slope = ((endY-startY)/(endX-startX));
	}

	public void calculateLengths()
	{
		this.length = Math.sqrt((Math.pow((endX-startX), 2)+Math.pow((endY-startY), 2)));
		this.scaledLength = (length/10);
	}

	public void calculateAngle()
	{
		this.angle = Math.atan(((endX-startX)/(endY-startY)));
	}

	public void convertToUnitVec(int xInit, int yInit, int xFin, int yFin)
	{
		unitVector = (((xFin-xInit)/10) + "i + " +  (-(yFin-yInit)/10) + "j");
	}

	public String getUnitVec()
	{
		return this.unitVector;
	}

	public int getStrtX()
	{
		return this.startX;
	}
	public int getEndX()
	{
		return this.endX;
	}
	public int getStrtY()
	{
		return this.startY;
	}
	public int getEndY()
	{
		return this.endY;
	}
	public double getSlope()
	{
		return this.slope;
	}
	public double getLength()
	{
		return this.length;
	}
	public double getScaledLength()
	{
		return this.scaledLength;
	}
	public double getAngle()
	{
		return this.angle;
	}
	public int getDrawCoordX()
	{
		return this.drawCoordX;
	}
	public int getDrawCoordY()
	{
		return this.drawCoordY;
	}
	public int getDrawCoordXF()
	{
		return this.drawCoordXF;
	}
	public int getDrawCoordYF()
	{
		return this.drawCoordYF;
	}
	public Boolean getVisibility()
	{
		return this.visibility;
	}
}
